package com.dyw.spzx.manager.controller;

import com.dyw.spzx.common.log.annotation.Log;
import com.dyw.spzx.manager.service.SysUserService;
import com.dyw.spzx.model.dto.system.AssginRoleDto;
import com.dyw.spzx.model.dto.system.SysUserDto;
import com.dyw.spzx.model.entity.system.SysUser;
import com.dyw.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户接口")
@RestController
@RequestMapping("/admin/system/sysUser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @Operation(summary = "查询用户列表")
    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysUser>> findByPage(SysUserDto sysUserDto, @PathVariable(value = "pageNum") Integer pageNum,
                                                @PathVariable(value = "pageSize") Integer pageSize) {

        PageInfo<SysUser> userPageInfo = sysUserService.findSysUserByPage(sysUserDto,pageNum,pageSize);


        return Result.ok(userPageInfo);
    }

    @Log(title = "角色添加",businessType = 0) //添加Log注解，设置属性
    @Operation(summary = "保存用户信息")
    @PostMapping("/saveSysUser")
    public Result saveSysUser(@RequestBody SysUser sysUser){
        sysUserService.saveSysUser(sysUser);
        return Result.ok(null);
    }
    @Operation(summary = "修改用户信息")
    @PutMapping("/updateSysUser")
    public Result updateSysUser(@RequestBody SysUser sysUser){
        sysUserService.updateSysUser(sysUser);
        return Result.ok(null);
    }

    @Operation(summary = "删除用户信息")
    @DeleteMapping("/deleteById/{userId}")
    public Result deleteById(@PathVariable("userId") Integer userId){
        sysUserService.deleteById(userId);
        return Result.ok(null);
    }

    @Operation(summary = "保存用户角色数据")
    @PostMapping("doAssign")
    public Result doAssign(@RequestBody AssginRoleDto assginRoleDto){
        sysUserService.doAssign(assginRoleDto);
        return Result.ok(null);
    }




}
